<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <link rel="shortcut icon" type="image/x-icon" href="./favicon.ico">
    <title>获取大陆省市区</title>
    <%--<script type="text/javascript" src="http://localhost:9080/js/jquery-3.1.0.min.js">
    </script>--%>
    <script>
        function getPlace(){
            //ajaxYS("http://localhost:8080/place/insertAll");
            post("http://localhost:8080/geoplace/showPlace");
        }
        function ajaxYS(url){
            var myXMLHttpRequest = null;
            if (window.ActiveXObject) {
                myXMLHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } else {
                myXMLHttpRequest = new XMLHttpRequest();
            }
            // var url = "http://localhost:8080/pinyin/getHead";
            var sourceurl=document.getElementById("sourceurl").value;
             var postData = {
                "sourceurl": sourceurl
            }
            myXMLHttpRequest.open("post", url, true);
            myXMLHttpRequest.setRequestHeader("Content-Type","application/json");
            //myXMLHttpRequest.send(postData);
            myXMLHttpRequest.send("sourceurl=http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2015");
            myXMLHttpRequest.onreadystatechange = function(){
                if (myXMLHttpRequest.readyState == 4) {
                    if(myXMLHttpRequest.status == 200){
                      document.getElementById("result").value=myXMLHttpRequest.responseText;
                    }
                }
            }
        }
        //方法2
        function createXMLHTTPRequest() {
            //1.创建XMLHttpRequest对象
            //这是XMLHttpReuquest对象无部使用中最复杂的一步
            //需要针对IE和其他类型的浏览器建立这个对象的不同方式写不同的代码
            var xmlHttpRequest;
            if (window.XMLHttpRequest) {
                //针对FireFox，Mozillar，Opera，Safari，IE7，IE8
                xmlHttpRequest = new XMLHttpRequest();
                //针对某些特定版本的mozillar浏览器的BUG进行修正
                if (xmlHttpRequest.overrideMimeType) {
                    xmlHttpRequest.overrideMimeType("text/xml");
                }
            } else if (window.ActiveXObject) {
                //针对IE6，IE5.5，IE5
                //两个可以用于创建XMLHTTPRequest对象的控件名称，保存在一个js的数组中
                //排在前面的版本较新
                var activexName = [ "MSXML2.XMLHTTP", "Microsoft.XMLHTTP" ];
                for ( var i = 0; i < activexName.length; i++) {
                    try {
                        //取出一个控件名进行创建，如果创建成功就终止循环
                        //如果创建失败，回抛出异常，然后可以继续循环，继续尝试创建
                        xmlHttpRequest = new ActiveXObject(activexName[i]);
                        if(xmlHttpRequest){
                            break;
                        }
                    } catch (e) {
                    }
                }
            }
            return xmlHttpRequest;
        }
        function post(url){
            var req = createXMLHTTPRequest();
            if(req){
                req.open("POST", url, true);
                req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8;");
                req.send("sourceurl=http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2015");
                req.onreadystatechange = function(){
                    if(req.readyState == 4){
                        if(req.status == 200){
                            document.getElementById("result").value=req.responseText;
                        }else{
                            alert("error");
                        }
                    }
                }
            }
        }
    </script>
</head>
<body>
输入网址：<input type="text" id="sourceurl" value="http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2015" style="width:500px;">
<hr>
<button onclick="getPlace()">得到所有省市区</button>
<p>结果显示：</p>
<textarea cols="80" rows="40" id="result"></textarea>
</body>
</html>